* Table C5: Socioeconomic status, academic achievement, and ROL characteristics

********************************************************************************
************************** Prepare data ****************************************
********************************************************************************

clear all
use GPA11_3_std funded_only unfunded_only disadv using "${data_students}", clear

gen GPA11_3_std_m = GPA11_3_std == .
label variable GPA11_3_std_m "11th-grade GPA (missing)"

replace GPA11_3_std = 0 if GPA11_3_std_m == 1


********************************************************************************
************************** Prepare table ***************************************
********************************************************************************

** Column 1 ----------------------------------------------------------------
qui reg funded_only disadv, r
local i = 1

	local est_disadv_`i': 	display %4.3f _b[disadv]
	local se_disadv_`i': 		display %4.3f _se[disadv]
	local p_disadv_`i'_long: 	display (2 * ttail(e(df_r), abs(_b[disadv]/_se[disadv])))
	local r2_`i': display %4.3f e(r2)
	
	if 		`p_disadv_`i'_long'<=0.01	local stars_disadv_`i' "$^{***}$"
	else if `p_disadv_`i'_long'<=0.05	local stars_disadv_`i' "$^{**}$"
	else if `p_disadv_`i'_long'<=0.1	local stars_disadv_`i' "$^{*}$"
	else 						local stars_disadv_`i' ""

** Column 2 ----------------------------------------------------------------	
qui reg funded_only GPA11_3_std GPA11_3_std_m, r
local i = 2

	local est_gpa_`i': 	display %4.3f _b[GPA11_3_std]
	local se_gpa_`i': 		display %4.3f _se[GPA11_3_std]
	local p_gpa_`i'_long: 	display (2 * ttail(e(df_r), abs(_b[GPA11_3_std]/_se[GPA11_3_std])))
	local r2_`i': display %4.3f e(r2)
	
	if 		`p_gpa_`i'_long'<=0.01	local stars_gpa_`i' "$^{***}$"
	else if `p_gpa_`i'_long'<=0.05	local stars_gpa_`i' "$^{**}$"
	else if `p_gpa_`i'_long'<=0.1	local stars_gpa_`i' "$^{*}$"
	else 						local stars_gpa_`i' ""

** Column 3 ----------------------------------------------------------------
qui reg funded_only disadv GPA11_3_std GPA11_3_std_m, r
local i = 3

	local est_disadv_`i': 	display %4.3f _b[disadv]
	local se_disadv_`i': 		display %4.3f _se[disadv]
	local p_disadv_`i'_long: 	display (2 * ttail(e(df_r), abs(_b[disadv]/_se[disadv])))
	local r2_`i': display %4.3f e(r2)
	
	if 		`p_disadv_`i'_long'<=0.01	local stars_disadv_`i' "$^{***}$"
	else if `p_disadv_`i'_long'<=0.05	local stars_disadv_`i' "$^{**}$"
	else if `p_disadv_`i'_long'<=0.1	local stars_disadv_`i' "$^{*}$"
	else 						    local stars_disadv_`i' ""
	
	local est_gpa_`i': 	display %4.3f _b[GPA11_3_std]
	local se_gpa_`i': 		display %4.3f _se[GPA11_3_std]
	local p_gpa_`i'_long: 	display (2 * ttail(e(df_r), abs(_b[GPA11_3_std]/_se[GPA11_3_std])))
	
	if 		`p_gpa_`i'_long'<=0.01	local stars_gpa_`i' "$^{***}$"
	else if `p_gpa_`i'_long'<=0.05	local stars_gpa_`i' "$^{**}$"
	else if `p_gpa_`i'_long'<=0.1	local stars_gpa_`i' "$^{*}$"
	else 						local stars_gpa_`i' ""	

** Column 4 ----------------------------------------------------------------
qui reg unfunded_only disadv, r
local i = 4

	local est_disadv_`i': 	display %4.3f _b[disadv]
	local se_disadv_`i': 		display %4.3f _se[disadv]
	local p_disadv_`i'_long: 	display (2 * ttail(e(df_r), abs(_b[disadv]/_se[disadv])))
	local r2_`i': display %4.3f e(r2)
	
	if 		`p_disadv_`i'_long'<=0.01	local stars_disadv_`i' "$^{***}$"
	else if `p_disadv_`i'_long'<=0.05	local stars_disadv_`i' "$^{**}$"
	else if `p_disadv_`i'_long'<=0.1	local stars_disadv_`i' "$^{*}$"
	else 						local stars_disadv_`i' ""

** Column 5 ----------------------------------------------------------------	
qui reg unfunded_only GPA11_3_std GPA11_3_std_m, r
local i = 5

	local est_gpa_`i': 	display %4.3f _b[GPA11_3_std]
	local se_gpa_`i': 		display %4.3f _se[GPA11_3_std]
	local p_gpa_`i'_long: 	display (2 * ttail(e(df_r), abs(_b[GPA11_3_std]/_se[GPA11_3_std])))
	local r2_`i': display %4.3f e(r2)
	
	if 		`p_gpa_`i'_long'<=0.01	local stars_gpa_`i' "$^{***}$"
	else if `p_gpa_`i'_long'<=0.05	local stars_gpa_`i' "$^{**}$"
	else if `p_gpa_`i'_long'<=0.1	local stars_gpa_`i' "$^{*}$"
	else 						local stars_gpa_`i' ""

** Column 6 ----------------------------------------------------------------
qui reg unfunded_only disadv GPA11_3_std GPA11_3_std_m, r
local i = 6

	local est_disadv_`i': 	display %4.3f _b[disadv]
	local se_disadv_`i': 		display %4.3f _se[disadv]
	local p_disadv_`i'_long: 	display (2 * ttail(e(df_r), abs(_b[disadv]/_se[disadv])))
	local r2_`i': display %4.3f e(r2)
	
	if 		`p_disadv_`i'_long'<=0.01	local stars_disadv_`i' "$^{***}$"
	else if `p_disadv_`i'_long'<=0.05	local stars_disadv_`i' "$^{**}$"
	else if `p_disadv_`i'_long'<=0.1	local stars_disadv_`i' "$^{*}$"
	else 						    local stars_disadv_`i' ""
	
	local est_gpa_`i': 	display %4.3f _b[GPA11_3_std]
	local se_gpa_`i': 		display %4.3f _se[GPA11_3_std]
	local p_gpa_`i'_long: 	display (2 * ttail(e(df_r), abs(_b[GPA11_3_std]/_se[GPA11_3_std])))
	
	if 		`p_gpa_`i'_long'<=0.01	local stars_gpa_`i' "$^{***}$"
	else if `p_gpa_`i'_long'<=0.05	local stars_gpa_`i' "$^{**}$"
	else if `p_gpa_`i'_long'<=0.1	local stars_gpa_`i' "$^{*}$"
	else 						local stars_gpa_`i' ""	

cap file close sumstat
file open sumstat using "${tableC5}", write replace
file write sumstat "\begin{tabular}{l c c c c c c c} \\ \hline\hline" _n
file write sumstat "Dependent variable & \multicolumn{3}{c}{Ranked state-funded contract} & & \multicolumn{3}{c}{Ranked self-funded contract} \\" _n
file write sumstat "                   & \multicolumn{3}{c}{exclusively}                  & & \multicolumn{3}{c}{exclusively} \\ \cline{2-4} \cline{6-8}" _n
file write sumstat " & (1) & (2) & (3) & & (4) & (5) & (6) \\ \hline" _n

local lab_var: variable label disadv

file write sumstat "`lab_var' & `est_disadv_1'`stars_disadv_1' & & `est_disadv_3'`stars_disadv_3'& & `est_disadv_4'`stars_disadv_4' & &  `est_disadv_6'`stars_disadv_6'\\ " _n
file write sumstat " & (`se_disadv_1') & &  (`se_disadv_3') & & (`se_disadv_4') & & (`se_disadv_6')  \\ " _n

local lab_var: variable label GPA11_3_std
file write sumstat "`lab_var' &  &  `est_gpa_2'`stars_gpa_2' & `est_gpa_3'`stars_gpa_3' & & & `est_gpa_5'`stars_gpa_5' & `est_gpa_6'`stars_gpa_6' \\ " _n
file write sumstat " &  & (`se_gpa_2') & (`se_gpa_3') &&&  (`se_gpa_5') &  (`se_gpa_6') \\ \hline" _n

qui sum unfunded_only if disadv == 0
local mean_unfunded: display %4.3f r(mean)
qui sum funded_only if disadv == 0
local mean_funded: display %4.3f r(mean)

file write sumstat " Mean outcome (non-disadvd.) & `mean_funded' & `mean_funded' & `mean_funded' && `mean_unfunded' & `mean_unfunded' & `mean_unfunded' \\ " _n
file write sumstat "R-squared                   & `r2_1' & `r2_2' & `r2_3' && `r2_4' & `r2_5' & `r2_6' \\ \hline\hline" _n

count
local sample_size: display %12.0fc r(N)

count if GPA11_3_std_m == 1
local missing_gpa: display %12.0fc r(N)

file write sumstat "\multicolumn{8}{p{16.5cm}}{{\it Notes}: The table presents the coefficient of linear regressions of ROL characteristics (such as whether an applicant ranked state-funded contracts exclusively on her ROL (columns (1)--(3)) and whether an applicant ranked self-funded contracts exclusively on her ROL (columns (4)--(6))) on socioeconomic status and academic achievement. The sample includes $`sample_size'$ applicants. The regressions include indicators for missing values of standardized 11th-grade GPA ($`missing_gpa'$ applicants). Robust standard errors are in parentheses.} \\ " _n
file write sumstat "\multicolumn{8}{p{16.5cm}}{***: p<0.01, **: p<0.05, *: p<0.1.}" _n
file write sumstat "\end{tabular}" _n
file close sumstat